import $ from "./jquery"
import  "./401.js"
let filenames = [];
$(function () {

    //临时上传

    $("#uploadImg").change(function () {
        let files = this.files;
        let fd = new FormData();
        for (let i = 0; i < files.length; i++) {
            fd.append("file", files[i]);
        }
        // console.log(files)
        $.ajax({
            url: "http://192.168.30.63:3000/banner/upload",
            type: "post",
            data: fd,
            processData: false,
            contentType: false,
            success(res) {
                // console.log(res);
                if (res.code == 200) {
                    res.files.forEach(item => {
                        let image = `<img src="http://192.168.30.63:3000/temp/${item.filename}" alt="" width="50px" height="50px"/>`
                        $(".div").append(image);
                        filenames.push(item.filename);
                    })
                }
            }
        })
    })
    // 确认上传
    $("#upload_sure").click(function () {
        $.post('http://192.168.30.63:3000/banner/upload_sure', { filenames: filenames.join() }, function (res) {
            alert(res.code == 200 ? "上传成功" : "上传失败");
        })
    })
})
